package com.timmy.video.ui.fragment;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.timmy.video.R;

/**
 * @Auther: Timmy
 * @Data: 2017/7/22
 * @Fuction:
 */

public class AlertDialogFragment extends DialogFragment {

    public interface DialogFragmentDataImp {//定义一个与Activity通信的接口，使用该DialogFragment的Activity须实现该接口

        void showMessage(String message);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        // getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        // getDialog().setTitle("这是标题");
         setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        return super.onCreateView(inflater, container, savedInstanceState);
    }


    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        super.onStart();

        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;

        window.setAttributes(windowParams);
    }

    public static AlertDialogFragment newInstance(String message) {
        //创建一个带有参数的Fragment实例
        AlertDialogFragment fragment = new AlertDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString("message", message);
        fragment.setArguments(bundle);//把参数传递给该DialogFragment
        return fragment;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // View customView = LayoutInflater.from(getActivity()).inflate(R.layout.base_cardview, null);

        View customView = getActivity().getLayoutInflater().inflate(R.layout.base_cardview, null);

        final Dialog dialog = new Dialog(getActivity());
        dialog.setContentView(customView);
         dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

        // dialog.getWindow().setBackgroundDrawable(new draw1);
         return dialog;


//        Button mBtnSure = (Button) customView.findViewById(R.id.yes);
//        Button mBtnCancel = (Button) customView.findViewById(R.id.no);
//        TextView mTvMsg = (TextView) customView.findViewById(R.id.message);
//
//        mTvMsg.setText(getArguments().getString("message"));//把传递过来的数据设置给TextView
//        mBtnSure.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                DialogFragmentDataImp imp = (DialogFragmentDataImp) getActivity();
//                imp.showMessage(getArguments().getString("message"));//对话框与Activity间通信，传递数据给实现了DialogFragmentDataImp接口的Activity
//                dismiss();
//            }
//        });
//        mBtnCancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dismiss();
//            }
//        });
        //return new AlertDialog.Builder(getActivity()).setView(customView).create();
    }

}